class RemoveStartWithItemTableForeignKeys < ActiveRecord::Migration
  def self.up
    remove_foreign_key(:items, :column => 'cat1_id')
    remove_foreign_key(:items, :column => 'cat2_id')
    remove_foreign_key(:items, :column => 'style_id')
    remove_foreign_key(:items, :brands)
    remove_foreign_key(:item_alliances, :users)
    remove_foreign_key(:item_pictures, :users)
    remove_foreign_key(:item_pictures, :items)
    remove_foreign_key(:item_ratings, :users)
    remove_foreign_key(:item_ratings, :items)
    remove_foreign_key(:item_rating_replies, :users)
    remove_foreign_key(:item_rating_replies, :column => 'item_comment_id')
    remove_foreign_key(:item_tags, :items)
    remove_foreign_key(:item_tags, :column => 'tag_id')
    remove_foreign_key(:item_rating_voles, :column => 'item_comment_id')
    remove_foreign_key(:item_statistics, :items)
    remove_foreign_key(:item_statistics, :item_alliances)
    remove_foreign_key(:item_recommends, :items)
    remove_foreign_key(:item_promotions, :items)
  end

  def self.down
    add_foreign_key(:items, :item_categories, :column => 'cat1_id', :dependent => :delete)
    add_foreign_key(:items, :item_categories, :column => 'cat2_id', :dependent => :delete)
    add_foreign_key(:items, :item_styles, :column => 'style_id', :dependent => :delete)
    add_foreign_key(:items, :brands, :column => 'brand_id', :dependent => :delete)
    add_foreign_key(:item_alliances, :users, :column => 'user_id', :dependent => :delete)
    add_foreign_key(:item_pictures, :users, :column => 'user_id', :dependent => :delete)
    add_foreign_key(:item_pictures, :items, :column => 'item_id', :dependent => :delete)
    add_foreign_key(:item_ratings, :users, :column => 'user_id', :dependent => :delete)
    add_foreign_key(:item_ratings, :items, :column => 'item_id', :dependent => :delete)
    add_foreign_key(:item_rating_replies, :users, :column => 'user_id', :dependent => :delete)
    add_foreign_key(:item_rating_replies, :item_ratings, :column => 'item_comment_id', :dependent => :delete)
    add_foreign_key(:item_tags, :items, :column => 'item_id', :dependent => :delete)
    add_foreign_key(:item_tags, :tags, :column => 'tag_id', :dependent => :delete)
    add_foreign_key(:item_rating_voles, :item_ratings, :column => 'item_comment_id', :dependent => :delete)
    add_foreign_key(:item_statistics, :items, :column => 'item_id', :dependent => :delete)
    add_foreign_key(:item_statistics, :item_alliances, :column => 'item_alliance_id', :dependent => :delete)
    add_foreign_key(:item_recommends, :items, :column => 'item_id', :dependent => :delete)
    add_foreign_key(:item_promotions, :items, :column => 'item_id', :dependent => :delete)
  end
end
